package com.gopay.common.cps.dao.cbrmb.impl;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbCustomsPaymentDAO;
import com.gopay.common.domain.cbrmb.customs.CbRmbCustomsPayment;

@Repository(value = "cbRmbCustomsPaymentDAO")
public class CbRmbCustomsPaymentDAOImpl extends BaseDAOImpl<CbRmbCustomsPayment, Serializable>
		implements CbRmbCustomsPaymentDAO {

	/**
	 * 获取待报关信息
	 */
	@Override
	public List<CbRmbCustomsPayment> getUndeclaredOrder() {
		String hql = "from CbRmbCustomsPayment where state = '00'";
		return findByHql(hql);
	}

	/**
	 * 获取超时失效信息
	 */
	@Override
	public List<CbRmbCustomsPayment> getTimeOutOrder() {
		Date timeOut = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 4));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(timeOut);
		String hql = "from CbRmbCustomsPayment where state = '01' and createTime <= to_date('" + date
				+ "', 'yyyy-MM-dd HH24:mm:ss')";
		return findByHql(hql);
	}

	@Override
	public CbRmbCustomsPayment findByGuid(String guid) {
		String hql = "from CbRmbCustomsPayment where guid='" + guid + "'";
		List<CbRmbCustomsPayment> payments = findByHql(hql);
		return payments.size() > 0 ? payments.get(0) : null;
	}

}
